package com.example.tests;

import java.util.Comparator;

public class ContactComparator implements Comparator<ContactData>{
	public int compare(ContactData contact1, ContactData contact2) {
		final int EQUAL = 0;
		
		if (contact1 == contact2) return EQUAL;
		
		int comparison = contact1.getLastName().toLowerCase().compareTo(contact2.getLastName().toLowerCase());
		if (comparison != EQUAL) return comparison;
		
		comparison = contact1.getFirstName().toLowerCase().compareTo(contact2.getFirstName().toLowerCase());
		if (comparison != EQUAL) return comparison;
		
		comparison = contact1.getHomePhoneNr().toLowerCase().compareTo(contact2.getHomePhoneNr().toLowerCase());
		if (comparison != EQUAL) return comparison;

		comparison = contact1.getFirstEmailAddress().toLowerCase().compareTo(contact2.getFirstEmailAddress().toLowerCase());
		if (comparison != EQUAL) return comparison;

//		assert this.equals(other) : "compareTo inconsistent with equals";
		
		return EQUAL;
		}	
	

}
